package com.orcamento.util;

import java.util.ArrayList;
import java.util.List;

import org.joda.time.DateTime;

public class CalendarUtil {
	
	public static DateTime toDate(int day, int month, int year) {
		return toDate(day, month, year, 0, 0, 0);
	}
	
	public static DateTime toDate(int day, int month, int year, int hour, int minute, int second) {
		return new DateTime(year, month, day, hour, minute, second);
	}

	public static int getCurrentYear() {
		return new DateTime().getYear();
	}
	
	public static int getCurrentMonth() {
		return new DateTime().getMonthOfYear();
	}
	
	public static String toString(DateTime date, String format) {
		try {
			return date.toString(format);
		} catch( Exception e ) {
			return null;
		}
	}

	public static List<Period> getAllPeriods(DateTime startDate) {
		List<Period> periods = new ArrayList<Period>();
		DateTime today = new DateTime();
		Period currentPeriod = new Period( today.getYear(), today.getMonthOfYear() );
		
		Period period = new Period( startDate.getYear(), startDate.getMonthOfYear() );
		periods.add( period );
		
		while( ! currentPeriod.equals(period) ) {
			period = period.next();
			periods.add( period );
		}
		
		return periods;
	}
	
}
